
package com.hlkj.pay.app.merchant.ext.impl.jhpay.handle;
/*
 * Hlpay-Plus aggregate payment system.
 * Copyright (c) 2024-2025 Hlpay Team Copyright has the right of final interpretation.
 */

import org.springframework.util.StringUtils;

import com.hlkj.framework.common.pojo.CommonResult;
import com.hlkj.framework.common.util.json.JsonUtils;
import com.hlkj.pay.app.merchant.ext.impl.jhpay.dto.JhPayAppChannelParams;
import com.hlkj.pay.app.merchant.ext.impl.jhpay.dto.JhPayConfig;
import com.hlkj.pay.common.PayResultCode;
import com.hlkj.pay.infrastructure.model.merchant.MerchantAppChannelDO;
import com.hlkj.pay.infrastructure.model.pay.ProviderChannelConfigDO;

/**
 * @author HlpayTeam
 * @date 2025/02/05 10:39
 */
public class JhPayMerchantCommonParamsHandle {

    /**
     * 
     * @param providerChannelConfigDO
     * @param test
     * @return
     */
    public CommonResult<JhPayConfig> jhPayConfig(ProviderChannelConfigDO providerChannelConfigDO, boolean test) {
        String paramsConfig = providerChannelConfigDO.getParamsConfig();
        if (StringUtils.isEmpty(paramsConfig)) {
            return CommonResult.error(PayResultCode.PAY_CHANNEL_CONFIG_NOT_EXITS);
        }
        // 配置转换
        JhPayConfig jhPayConfig = null;
        try {

            jhPayConfig = JsonUtils.parseObject(paramsConfig, JhPayConfig.class);
            return CommonResult.success(jhPayConfig);
        }
        catch (Exception e) {
            String format = String.format(PayResultCode.PAY_CHANNEL_CONFIG_ERROR.getMsg(), "工行");
            return CommonResult.error(PayResultCode.PAY_CHANNEL_CONFIG_NOT_EXITS.getCode(), format);
        }
    }
    public JhPayAppChannelParams jhPayAppChannelParams(MerchantAppChannelDO merchantAppChannelDO) {
        return JsonUtils.parseObject(merchantAppChannelDO.getAppConfigJson(), JhPayAppChannelParams.class);
    }

    public String payUrl(boolean test){
        if(test){
            return "https://dev-pay-jhpay.xscashier.com/oapi";
        }
        return "https://dev-pay-jhpay.xscashier.com/oapi";
    }

}
